package interfaces;

import com.dropbox.sync.android.DbxAccount;
import com.dropbox.sync.android.DbxAccountManager;
import com.example.falai.R;
import com.example.falai.R.id;
import com.example.falai.R.layout;
import com.example.falai.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TesteActivity extends Activity {
	private DbxAccountManager mAccountManager;
	private DbxAccount mAccount;
	
    private static final String appKey = "06zoqg9s32uabzs";
    private static final String appSecret = "cnze6mq1gtzx9j2";
    static final int REQUEST_LINK_TO_DBX = 0;
    
    private Button btnTeste;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_teste);
		mAccountManager = DbxAccountManager.getInstance(getApplicationContext(), appKey, appSecret);
		btnTeste = (Button) findViewById(R.id.btnTeste);
		btnTeste.setOnClickListener(new OnClickListener() {
	        @Override
	        public void onClick(View v) {
	            mAccountManager.startLink((Activity)TesteActivity.this, REQUEST_LINK_TO_DBX);
	        }
	    });

	    if (mAccountManager.hasLinkedAccount()) {
	        mAccount = mAccountManager.getLinkedAccount();
	        btnTeste.setVisibility(View.GONE);
	        // ... Now display your own UI using the linked account information.
	    } else {
	    	btnTeste.setVisibility(View.VISIBLE);
	    }
	}
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
	    if (requestCode == REQUEST_LINK_TO_DBX) {
	        if (resultCode == Activity.RESULT_OK) {
	            mAccount = mAccountManager.getLinkedAccount();
	            btnTeste.setVisibility(View.GONE);
	            // ... Now display your own UI using the linked account information.
	        } else {
	            // ... Link failed or was cancelled by the user.
	        }
	    } else {
	        super.onActivityResult(requestCode, resultCode, data);
	    }
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.teste, menu);
		return true;
	}

}
